package com.yzwu.stream;

import com.yzwu.lambda.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @author yzwu
 * @date 2022/5/28 5:12 PM
 */
public class StreamAPI {
    List<Employee> employees= Arrays.asList(
            new Employee(301,"张三",18,9999.99, Employee.Status.FREE),
            new Employee(302,"李四",58,5555.55, Employee.Status.BUSY),
            new Employee(303,"王五",26,3333.33, Employee.Status.VOCATION),
            new Employee(304,"赵六",36,6666.66, Employee.Status.FREE),
            new Employee(305,"田七",12,8888.88, Employee.Status.BUSY)
    );
    @Test
    public void test1(){
        int[] nums = {1, 2, 3, 4, 5};
        Arrays.stream(nums)
                .map(x -> x * x)
                .forEach(System.out::println);
    }
    @Test
    public void test2(){
        //用map-reduce 数一数employee
        Optional<Integer> reduce = employees.stream()
                .map(e -> 1)
                .reduce(Integer::sum);
        System.out.println(reduce.get());
    }
    @Test
    public void test3(){

    }
}
